Repository navigation
Leave the caller's writer open in the Newtonsoft serialization provider [patch] - #109
Merged
Merged
Conversation
…er [patch] TrySerialize disposed a JsonTextWriter with CloseOutput left at true, which closed the caller's TextWriter and its stream, so the next call threw ObjectDisposedException instead of returning false. The JSON writer now leaves the output open and flushes it, and TrySerialize returns false on IOException and ObjectDisposedException as the System.Text.Json provider does. Deserialize also returns default for shape-mismatched JSON instead of letting JsonSerializationException escape. Fixes #72 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SWgHqHW7R9hBKkZ6Zzx5Lg
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SWgHqHW7R9hBKkZ6Zzx5Lg
Contributor
Author
|
Generated by Claude Code |
Resolve the RoundTripTests conflict by keeping both this branch's writer-left-open and shape-mismatch tests and main's Serialization_Ignores_Members_The_Target_Type_Lacks test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012HSF4Gj3hc8AnJp7yx5gHS
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #72
What changed
NewtonsoftJsonSerializationProvider.TrySerializenow creates itsJsonTextWriterwithCloseOutput = falseand flushes it after serializing. Before, disposing it closed the caller'sTextWriterand the stream underneath. The nextTrySerializeorTrySerializeAsynccall into that writer then threwObjectDisposedExceptioninstead of returningfalse.TrySerializenow also catchesIOExceptionandObjectDisposedExceptionand returnsfalse, asJsonSerializationProvideralready does.Deserialize<T>now catchesJsonSerializationException, so JSON whose shape doesn't matchT(for example[1,2]read into a class) returnsdefault. Previously the exception escaped, while the System.Text.Json provider already returneddefault. This is the second gap the issue describes.Tests
I added two contract tests to
RoundTripTests, following the issue's acceptance criteria:Serialization_TrySerialize_Twice_Into_One_StreamWriter_Leaves_It_Openruns against every registeredISerializationProvider. It serializes twice into oneStreamWriterover aMemoryStream. Both calls must returntrue, the stream must still be writable, and both documents must be present.Serialization_Json_Deserialize_ShapeMismatch_Returns_Defaultruns against every JSON provider (FileExtension == ".json").I reverted the provider change and reran these tests: only the Newtonsoft rows of both tests fail, and every other provider already passes. With the fix they pass. The full suite passes locally (1022 tests).
🤖 Generated with Claude Code
https://claude.ai/code/session_01SWgHqHW7R9hBKkZ6Zzx5Lg
Generated by Claude Code